package com.cyy.util;

import java.sql.*;

public class dbUtil {
    public static Connection getConnection() throws ClassNotFoundException, SQLException {
        Connection connection = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            connection = DriverManager.getConnection("jdbc:mysql://43.138.182.11:3306/Data?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT", "root", "123456");
        }catch (Exception e)
        {
            System.out.println("数据库连接失败");
            e.printStackTrace();
        }
        return connection;
    }

    public static void close(ResultSet resultSet, Statement statement,Connection connection) throws SQLException {
        if(resultSet!=null){
            resultSet.close();
        }
        if(statement!=null){
            statement.close();
        }
        if(connection!=null){
            connection.close();
        }
    }
}
